#ifndef _BINHEAP_H
#define _BINHEAP_H
#include <stddef.h>
typedef void *ElementType;
struct HeapStruct;
typedef struct HeapStruct *PriorityQueue;
typedef int Index;

typedef int (*HeapIfNull)(ElementType a);
//a > b, ret > 0; a < b, ret <0; a = b, ret = 0
typedef int (*HeapCompare)(ElementType a, ElementType b);
//from b to a
typedef int (*HeapCopy)(ElementType *a, ElementType b);
typedef int (*HeapGenMinEle)(ElementType *minPos, int minPro);
typedef int (*HeapReleaseMinEle)(ElementType *minPos);
typedef int (*HeapPrintEle)(ElementType a);

#define MinData (1 << 31)
PriorityQueue Initialize(
    int Capacity,
    HeapIfNull _heap_if_null,
    HeapCompare _heap_compare,
    HeapCopy _heap_copy,
    HeapGenMinEle _gen_min_ele,
    HeapReleaseMinEle _release_min_ele,
    HeapPrintEle _print_ele);

void Destory(PriorityQueue H);
void MakeEmpty(PriorityQueue H);
void Insert(ElementType X, PriorityQueue H);
ElementType DeleteMin(PriorityQueue H);
ElementType FindMin(PriorityQueue H);
int IsEmpty(PriorityQueue H);
int IsFull(PriorityQueue H);
void PrintTree(PriorityQueue H);
#define MinPQSize 10

//如果我们有办法得知关键字的位置，那么下面的方法是有益的
void DecreaseKey(ElementType *X, int Change, PriorityQueue H);
void IncreaseKey(ElementType *X, int Change, PriorityQueue H);
void Delete(ElementType *X, PriorityQueue);

struct HeapStruct
{
    int Capacity;
    int Size;
    HeapIfNull _heap_if_null;
    HeapCompare _heap_compare;
    HeapCopy _heap_copy;
    HeapGenMinEle _gen_min_ele;
    HeapReleaseMinEle _release_min_ele;
    HeapPrintEle _print_ele;
    //index 1为根节点 2index和2index + 1为节点的两个子节点
    ElementType *ElementList;
};

#endif
